package com.example.jdshopdeail.fragment;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.example.jdshopdeail.R;
import com.example.jdshopdeail.adapter.CardAdapter;
import com.example.jdshopdeail.base.BaseFragment;
import com.example.jdshopdeail.bean.TestBean;
import com.example.jdshopdeail.tantan.CardConfig;
import com.example.jdshopdeail.tantan.OverLayCardLayoutManager;
import com.example.jdshopdeail.tantan.TanTanCallback;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author: njb
 * @date: 2020/3/24 0024 10:47
 * @desc: 产品案例
 */
public class FMProductCase extends BaseFragment {
    @BindView(R.id.rv_product)
    RecyclerView rvProduct;
    private CardAdapter cardAdapter;

    @Override
    protected void loadData() {
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fm_product_case;
    }

    @Override
    protected void initView() {
       initAdapter();
    }

    private void initAdapter() {
        List<TestBean> datas = new ArrayList<>();
        for(int i=0;i<10;i++){
            TestBean swipeCardBean = new TestBean();
            swipeCardBean.setUrl( "http://imgs.ebrun.com/resources/2016_03/2016_03_25/201603259771458878793312_origin.jpg");
            swipeCardBean.setName("小姐姐");
            datas.add(swipeCardBean);
        }
        cardAdapter = new CardAdapter(datas);
        rvProduct.setLayoutManager(new OverLayCardLayoutManager());
        rvProduct.setAdapter(cardAdapter);
        CardConfig.initConfig(context);
        final TanTanCallback callback = new TanTanCallback(rvProduct, cardAdapter, datas);
        final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(rvProduct);
        Log.d("--count--",  getCount(rvProduct) + "");

    }

    private int getCount(ViewGroup viewGroup){
        int count = viewGroup.getChildCount();
        for(int i=0;i<count;i++){
            View child=viewGroup.getChildAt(i);
            if(child instanceof ViewGroup){
                //如果子View是ViewGroup，则用递归获取子View数量
                int childCount = getCount((ViewGroup)child);
                count+=childCount;
            }else {
                count++;
            }
        }
        return count;
    }

    @Override
    protected void addListener() {

    }
}
